"use strict";
const common_vendor = require("../../common/vendor.js");
const api_search = require("../../api/search.js");
const utils_message = require("../../utils/message.js");
require("../../utils/request.js");
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const hotSingerList = common_vendor.ref([]);
    const keyword = common_vendor.ref("");
    const timerSearchResult = common_vendor.ref([]);
    common_vendor.ref([]);
    const historyRecordList = common_vendor.ref([]);
    common_vendor.onLoad(() => {
      getHotSingerListMethod();
      historyRecordList.value = JSON.parse(common_vendor.index.getStorageSync("HISTORY"));
      console.log(historyRecordList.value);
    });
    const timerSearch = () => {
      if (keyword.value == "") {
        timerSearchResult.value = [];
        return;
      }
      timerSearchMethod();
    };
    const setHistoryRecord = () => {
      historyRecordList.value.push(keyword.value);
      common_vendor.index.setStorageSync("HISTORY", JSON.stringify(historyRecordList.value));
      keyword.value = "";
    };
    const getHotSingerListMethod = async () => {
      try {
        let result = await api_search.searchApi.reqHotSearch();
        if (result.code == 200) {
          hotSingerList.value = result.data;
        }
      } catch (error) {
        console.log(error);
        utils_message.showToast("获取歌曲热搜失败", "error");
      }
    };
    const timerSearchMethod = async () => {
      try {
        let result = await api_search.searchApi.reqTimerSearch({ keywords: keyword.value, limit: 10 });
        if (result.code == 200) {
          timerSearchResult.value = result.result.songs;
        }
      } catch (error) {
        console.log(error);
        utils_message.showToast("实时搜索失败", "error");
      }
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o([($event) => keyword.value = $event.detail.value, timerSearch]),
        b: keyword.value,
        c: common_vendor.o(setHistoryRecord),
        d: timerSearchResult.value.length > 0
      }, timerSearchResult.value.length > 0 ? {
        e: common_vendor.t(keyword.value),
        f: common_vendor.f(timerSearchResult.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.name),
            b: index
          };
        })
      } : {
        g: common_vendor.f(historyRecordList.value, (item, k0, i0) => {
          return {
            a: common_vendor.t(item),
            b: item
          };
        }),
        h: common_vendor.f(hotSingerList.value, (hot, index, i0) => {
          return {
            a: common_vendor.t(index + 1),
            b: common_vendor.t(hot.searchWord),
            c: index
          };
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-308a4d57"], ["__file", "D:/Desktop/cloud_yy/src/pages/search/index.vue"]]);
wx.createPage(MiniProgramPage);
